<?php

function head() {

	// header van de pagina

		$css = $_GET["css"];
	
		echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
		<HTML>
		<HEAD>";
		
		if (!$css) {
			echo "<SCRIPT LANGUAGE=\"JavaScript\">
			var imgObj=null, rTimer=null, attempts=2
			function checkURL() {
			if(rTimer==null) { // disable submit if in process
			imgObj=new Image()
			imgObj.onload=function(evt){processReturn()}
			imgObj.src= \"http://handboek.leer-php.nl/oke.gif\"
			rTimer=setTimeout(\"noResponse()\",4999); // 5 seconds for timeout
			}
			return false;
			}
			function processReturn() {
			if(rTimer!=null){clearTimeout(rTimer);rTimer=null}
			if(imgObj.width == 1) {
			document.location.href=\"http://handboek.leer-php.nl\";
			} 
			}
			function noResponse() {
			imgObj=rTimer=null
			}
			</SCRIPT>
			<TITLE> Handboek PHP </TITLE>
			</HEAD>";
		}

		if (!$css) {
			$css = "ceedee.css";
		}
		echo "<link href=\"$css\" rel=\"stylesheet\" type=\"text/css\">";

		echo "<BODY ";
		if (!$_GET["css"]) {
			echo "onLoad=\"checkURL();\"";
		}
		echo ">";

		echo "<table width=\"265\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" id=\"Table_01\">
			<tr>
				<td background=\"images/test_01.gif\">&nbsp;</td>
				<td height=\"25\" background=\"images/test_03.gif\">
					<div align=\"center\"><img src=\"images/test_02.gif\" width=\"174\" height=\"25\" alt=\"\"></div></td>
				<td background=\"images/test_03.gif\">&nbsp;</td>
			</tr>
			<tr>
				<td colspan=\"3\"><div align=\"center\"> <br>
			<table border=\"0\">
				  <tbody>";

}

function body() {

	// footer van de pagina

	echo "</tbody>
				</table>
			</div></td>
		</tr>
		<tr>
			<td height=\"3\" colspan=\"3\">&nbsp;</td>
		</tr>
		<tr>
			<td height=\"77\" colspan=\"3\" background=\"images/test_06a.gif\"><img src=\"images/test_06.gif\" width=\"265\" height=\"77\" alt=\"\"></td>
			</tr>
		</table>";

	echo "</BODY>
		</HTML>";

}

$db = mysql_connect("localhost", "handboekphp", "handboekphp")
        or die("Kan niet verbinden: " . mysql_error());
mysql_select_db("handboekphp", $db);

$onderwerpid = $_GET["onderwerpid"];
$showfile = $_GET["showfile"];

if ($onderwerpid) {

	// laat specifiek onderwerp zien

	head();

	$sql = "SELECT * FROM script WHERE onderwerpid=$onderwerpid ORDER BY volgorde";
	$resultaat  = mysql_query($sql); // voer SQL code uit


	
	echo "      <tr>
                  <td><span class=\"kop\">Voorbeeldscripts</span></td>
                </tr>"; // bovenste regel
	if ($resultaat) {
		while ($rij = mysql_fetch_array($resultaat)) {

		echo "<tr>";
		echo "<td><a href=\"".$_SERVER["PHP_SELF"]."?showfile=".$rij["scriptfile"]."\" target=\"_new\">[bron]</a> <a href=\"".$rij["scriptfile"]."\" target=\"_new\">[voer uit]</a> ".$rij["scriptnaam"]."</td>";
		echo "</tr>";

		}
	}

	echo "<tr><td>&nbsp;</td></tr>";	
	echo "<tr>";
	echo "<td><a href=\"index.php\">[Terug naar onderwerpen]</a></td>";
	echo "</tr>";

	body();


} elseif ($showfile) {

	$host = $_SERVER["DOCUMENT_ROOT"];
	show_source($host.$showfile);

}else {

	// laat een lijst met onderwerpen zien

	head();

	echo "      <tr>
                  <td><span class=\"kop\">Selecteer een onderwerp:</span></td>
                </tr>"; // bovenste regel


	$sql = "SELECT * FROM onderwerp ORDER BY volgorde";
	$resultaat  = mysql_query($sql); // voer SQL code uit
	if ($resultaat) {
		while ($rij = mysql_fetch_array($resultaat)) {

		echo "<tr>";
		echo "<td><a href=\"".$_SERVER["PHP_SELF"]."?onderwerpid=".$rij["onderwerpid"]."\">".$rij["naam"]."</a></td>";
		echo "</tr>";

		}

	echo "<tr><td>&nbsp;</td></tr>";	
	echo "<tr>";
	echo "<td><a href=\"http://www.leer-php.nl\" target=\"_new\">[Registreer je vandaag op leer-php.nl<br />Altijd het laatste nieuws en forums]</a></td>";
	echo "</tr>";

	}

	body();
}


?>